package jy.game.components.map;


import com.randy.fundation.JxFunc;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import jy.game.BasePojo;
import jy.game.components.music.JyMusics;
import wx.xml.simpleframework.xml.Attribute;
import wx.xml.simpleframework.xml.ElementList;
import wx.xml.simpleframework.xml.Root;

@Root(name = "map")
public class JyMap extends BasePojo {

    @Attribute(name = "name") public                     String              name;
    @Attribute(name = "pic") public                      String              pic;
    @Attribute(name = "desc") public                     String              desc;
    @ElementList(name = "musics", inline = true) public  List<JyMusics>      musicsValue;
    @ElementList(name = "mapunit", inline = true) public List<JyMapLocation> mapUnits;

    private boolean             initFlag;
    private List<JyMapLocation> locations = new ArrayList<>();
    private List<JyMapRole>     mapRoles  = new ArrayList<>();

    private List<JyMusics.JyMusic> musics = null;

    public List<JyMusics.JyMusic> getMusics() {
        if (musics == null) {
            musics = new ArrayList<>();

            JxFunc.of(musicsValue).ifPresent(value -> JxFunc.of(value.music).ifPresent(value1 -> musics.add(value1)));
        }
        return musics;
    }

    // (get) Token: 0x06000426 RID: 1062 RVA: 0x000044AC File Offset: 0x000026AC
    @Override public /*override*/ String getPK() {
        {
            return this.name;
        }
    }

//    public JyMusics.JyMusic getRandomMusic() {
////        if (this.musics.size() == 0) {
////            return null;
////        }
////        return this.musics.get(Tools.getRandomInt(0, this.musics.size() - 1));
////    }

    // (get) Token: 0x06000428 RID: 1064 RVA: 0x000044E6 File Offset: 0x000026E6
    public List<JyMapLocation> locations() {
        {
            this.init();
            return this.locations;
        }
    }

    // (get) Token: 0x06000429 RID: 1065 RVA: 0x000044F4 File Offset: 0x000026F4
    public List<JyMapRole> mapRoles() {
        {
            this.init();
            return this.mapRoles;
        }
    }

    private void init() {
        if (!this.initFlag) {
            if (this.name.contains("大地图")) {
                for (JyMapLocation item : this.mapUnits) {
                    this.locations.add(item);
                }
                this.initFlag = true;
                return;
            }
            for (JyMapLocation item2 : this.mapUnits) {
                this.mapRoles.add(item2);
            }
            this.initFlag = true;
        }
    }
}
